<template>
  <div class="mergeInfo">
    <basic-container>
      <el-dialog
        title="数据来源替换"
        :visible.sync="dialogVisible"
        @close="closed"
        width="950px">
        <div style="line-height: 40px;background-color: #fcf7f7;padding-left: 15px">
          <span>线路：</span><span>{{getLineName(formData.lineCode)}}</span>
          <span style="margin-left: 20px">站点：</span><span>{{getStationName(formData.lineCode,formData.stationCode)}}</span>
          <span style="margin-left: 20px"> TVM编号：</span><span>{{formData.tvmCode}}</span>
          <span style="margin-left: 20px"> 补币金额：</span><span>{{fenExYuangettoFixed(formData,'supplementMoney')}}</span>
          <span style="margin-left: 20px"> 卸载金额：</span><span>{{fenExYuangettoFixed2(Math.abs(formData.actualMoney+formData.supplementMoney-formData.handOutMoney))}}</span>
          <span style="margin-left: 20px"> 手工清出金额：</span><span>{{fenExYuangettoFixed(formData,'handOutMoney')}}</span>
          <span style="margin-left: 20px"> 合计清点收入金额：</span><span>{{heji((formData.actualMoney))}}</span>
        </div>
      <avue-crud
        ref="mergeInfo"
        :option="option"
        :table-loading="listLoading"
        :data="list"
        :page.sync="page">
        <template slot-scope="scope" slot="menu">
          <!-- <el-button type="text" v-if="(scope.row.auditStatus==0) && (scope.row.dataSource==2 ||scope.row.dataSource==3 ||scope.row.dataSource==4) && !Number(scope.row.sellAmount) && !Number(scope.row.investAmount) && !Number(scope.row.faretkAmount)" size="small" plain @click.stop="syncSystemAmounts(scope.row)">刷新</el-button> --> 
	  <el-button type="text" v-if="(scope.row.auditStatus==0) && (scope.row.dataSource==2 ||scope.row.dataSource==3 ||scope.row.dataSource==4) " size="small" plain @click.stop="syncSystemAmounts(scope.row)">刷新</el-button>
          <!-- <el-button type="text" v-if="scope.row.dataSource==1" size="small" plain hidden="true" @click.stop="queryJZDJ(scope.row)">查看</el-button> -->
          <el-button type="text" size="small" v-if="(scope.row.auditStatus==0)"  plain @click.stop="replaceSystemAmounts(scope.row)">替换</el-button>
        </template>
      </avue-crud>
        <div style="width: 100%;text-align: center">
          <el-button type="primary" size="mini"  @click="closed">返回</el-button>
        </div>
      </el-dialog>
    </basic-container>

    <JZDJ ref="JZDJ" v-if="isShowDia"></JZDJ>
  </div>

</template>

<script>
  import {getForm, postForm} from '@/api/gen/gen'
  import {mapGetters} from 'vuex';
  import JZDJ from './JZDJ';
  import { setSearchFiledsEmpty,getStationName,getLineName,fenExYuangettoFixed,getSCOrLCOrACC,fenExYuangettoFixed2
  } from "../../../../api/subwayRat/commonCheck";
  import {heji,replaceCengJiDatasourceSwAuTvmCashAmountHierarchyDifference,syncSystemAmounts
  } from '../../../../api/subwayRat/TVMRevenueVarianceAudit/differencesInAudit/fareDifferencesInAudit';
  import {
    getSwAuTvmDailyBillAssistDetail,
    getSwAuTvmDailyBillAssistList
  } from "../../../../api/subwayRat/TVMRevenueVarianceAudit.TvmChaYiDXC/TvmJiezhangdanjuxiecha";
  export default {
    name: 'huLianWangShouPiaojiDataInput',
    components:{JZDJ
    },
    data() {
      return {
        isShowDia:false,
        dialogVisible:false,
        option: {},
        listLoading: true,
        lineCodes:[],
        stationCodes:[],
        selectKeys:[],
        formData:{},
        selectKeyVals:[],
        searchForm:{},
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 20, // 每页显示多少条,
          isAsc: false// 是否倒序
        },
        list : []
      }
    },
    computed: {
      ...mapGetters(['permissions']),
    },
    watch: {
    },
    created() {
    },
    methods: {
      getStationName,getLineName,
      fenExYuangettoFixed,
      setSearchFiledsEmpty,
      fenExYuangettoFixed2,
      heji,
      async queryJZDJ(row){
        // let response = await getSwAuTvmDailyBillAssistList({relationid:row.id});
        // let data = response.data.data[0];
        // debugger
        // if(!data || 0==data.length){
        //   this.$message.warning("查询结账单据为空！");
        // }else{
          this.isShowDia = true;
          this.$nextTick(()=>{
            this.$refs.JZDJ.recallShow(this.formData);
          })
        // }
      },
      syncSystemAmounts(row){
        let th=this;
        syncSystemAmounts({dataSource:row.dataSource,row:JSON.stringify(this.formData)}).then(res=>{

          if(res.data.code==0){
            th.$message.success("操作成功！");
            th.$parent.getList();
            th.getLists(res.data.data);
            // th.closed();
          }else{
            th.$message.error("操作失败！");
          }
        }).catch(e=>{
          th.$message.error("操作失败！");
        })
      },
      getLists(row) {
        this.list = [];
        this.formData=row;
        this.listLoading = true;
        this.option={
          refreshBtn:false,
          columnBtn:false,
          emptyBtn: false,
          editBtn: false,
          delBtn: false,
          addBtn: false,
          border: true,
          index: true,
          indexLabel: '序号',
          page: true,
          align: 'center',
          menuWidth: 150,
          menuAlign: 'center',
          selection: false,
          reserveSelection: true,
          column: [{
            fixed: true,
            label: '主键',
            prop: 'id',
            span: 24,
            hide: true
          },{label: "数据来源", prop: "dataSource",formatter :function(row, value , label, column){
                return getSCOrLCOrACC(value);
              }},
            {label: "系统售票金额", prop: "sellAmount",formatter:function (row, value , label, column){
              var num =value / 100;
              num = num.toFixed(2);
              if(num == 'NaN')
                return '0.00';
              return num;
            }},
            {label: "系统充值金额", prop: "investAmount",formatter:function (row, value , label, column){
              var num =value / 100;
              num = num.toFixed(2);
              if(num == 'NaN')
                  return '0.00';
              return num;
            }},
            {label: "系统退款金额", prop: "faretkAmount",formatter:function (row, value , label, column){
              var num =value / 100;
              num = num.toFixed(2);
              if(num == 'NaN')
                return '0.00';
              return num;
            }},
            {label: "系统合计金额", prop: "heji",formatter:function (row, value , label, column){
              var num =value / 100;
              num = num.toFixed(2);
              if(num == 'NaN')
                return '0.00';
              return num;
            }},
            {label: "差异金额", prop: "chayi",formatter:function (row, value , label, column){
              var num =value / 100;
              num = num.toFixed(2);
              if(num == 'NaN')
                return '0.00';
              return num;
            }}
          ]
        };
        // let HJQC = row.actualMoney-row.supplementMoney+row.handOutMoney;
        // let HJQC = row.actualMoney-row.supplementMoney+row.handOutMoney;
        let HJQC = row.actualMoney;
        let JZDJ = {
            "id":row.id,
            "auditStatus":row.auditStatus,
            "dataSource":1,
            "sellAmount":row.tvmBillCashSellTicket,
            "investAmount":row.tvmBillCashRecharge,
            "faretkAmount":row.tvmBillCashReturn,
            "heji":row.tvmBillCashSellTicket+row.tvmBillCashRecharge+row.tvmBillCashReturn,
            "chayi":HJQC-(row.tvmBillCashSellTicket+row.tvmBillCashRecharge+row.tvmBillCashReturn)
        };
        let SC = {
          "id":row.id,
          "auditStatus":row.auditStatus,
            "dataSource":2,
            "sellAmount":row.scCashSellTicket,
            "investAmount":row.scCashRecharge,
            "faretkAmount":row.scCashReturn,
            "heji":row.scCashSellTicket+row.scCashRecharge+row.scCashReturn,
            "chayi":HJQC-(row.scCashSellTicket+row.scCashRecharge+row.scCashReturn)
        };
        let LC = {
          "id":row.id,
          "auditStatus":row.auditStatus,
            "dataSource":3,
            "sellAmount":row.lcCashSellTicket,
            "investAmount":row.lcCashRecharge,
            "faretkAmount":row.lcCashReturn,
            "heji":row.lcCashSellTicket+row.lcCashRecharge+row.lcCashReturn,
            "chayi":HJQC-(row.lcCashSellTicket+row.lcCashRecharge+row.lcCashReturn)
        };
        let ACC = {
          "id":row.id,
          "auditStatus":row.auditStatus,
            "dataSource":4,
            "sellAmount":row.accCashSellTicket,
            "investAmount":row.accCashRecharge,
            "faretkAmount":row.accCashReturn,
            "heji":row.accCashSellTicket+row.accCashRecharge+row.accCashReturn,
            "chayi":HJQC-(row.accCashSellTicket+row.accCashRecharge+row.accCashReturn)
        };
        let DT = {
          "id":row.id,
          "auditStatus":row.auditStatus,
            "dataSource":5,
            "sellAmount":row.singleCashSellTicket,
            "investAmount":row.singleCashRecharge,
            "faretkAmount":row.singleCashReturn,
            "heji":row.singleDeviceSysMoney?row.singleDeviceSysMoney:0,
            "chayi":HJQC-(row.singleDeviceSysMoney?row.singleDeviceSysMoney:0)
        };
        let FQX = {
          "id":row.id,
          "auditStatus":row.auditStatus,
            "dataSource":6,
            "sellAmount":0,
            "investAmount":0,
            "faretkAmount":0,
            "heji":row.boxAuditSysMoney?row.boxAuditSysMoney:0,
            "chayi":HJQC-(row.boxAuditSysMoney?row.boxAuditSysMoney:0)
        };
        this.list.push(JZDJ);
        this.list.push(SC);
        this.list.push(LC);
        this.list.push(ACC);
        this.list.push(DT);
        //this.list.push(FQX);
        this.listLoading = false;
      },
      replaceSystemAmounts(row){ //接口来源替换
        let th=this;
        replaceCengJiDatasourceSwAuTvmCashAmountHierarchyDifference({dataSource:row.dataSource,id:row.id}).then(res=>{
          if(res.data.code==0){
            th.$message.success("操作成功！");
            th.dialogVisible=false;
            th.$parent.getList();
            th.$parent.isShowMergeInfo=false;
          }else{
            th.$message.error("操作失败！");
          }
        }).catch(e=>{
          th.$message.error("操作失败！");
        })
      },
      closed(){
        this.dialogVisible=false;
        this.$parent.isShowMergeInfo=false;
      }
    },
    mounted() {

    }
  }
</script>
<style lang="scss">
  .huLianWangShouPiaojiDataInput {
    height: 100%;

    &__tree {
      padding-top: 3px;
      padding-right: 20px;
    }

    &__main {
      .el-card__body {
        padding-top: 0;
      }
    }
    .avue-form__group{

    }
  }
</style>
